#!/bin/sh

file="/home/nvidia/qc/QRelease/Bash/Guard.lock"
if [ -f "$file" ]; then
    echo "lock have."
    exit 0
else
    touch $file
fi

while true; do

        #每次循环沉睡15s
        sleep 15

        #启动一个循环，定时检查进程是否存在
        agent=`ps aux | grep QAgent | grep -v grep`
        if [ ! "$agent" ]; then
            #如果不存在就重新启动
            #echo "QAgent no."
	    setsid sudo /home/nvidia/qc/QRelease/Agent/QAgent &
            sleep 5
        fi
        
        capture=`ps aux | grep QCapture | grep -v grep`
        if [ ! "$capture" ]; then
            #如果不存在就重新启动
            #echo "QCapture no."
	    #setsid /home/nvidia/qc/QRelease/Capture/QCapture &
            setsid sudo bash /home/nvidia/qc/QRelease/Capture/mybash.sh &
            sleep 5
        fi

	control=`ps aux | grep QControl | grep -v grep`
        if [ ! "$control" ]; then
            #如果不存在就重新启动
            #echo "QControl no."
	    setsid /home/nvidia/qc/QRelease/Control/QControl &
            sleep 5
        fi
        
done
